package com.atguigu.gulimall.thirdparty;

import com.aliyuncs.http.HttpResponse;
import com.atguigu.gulimall.thirdparty.component.SmsComponent;
import com.atguigu.gulimall.thirdparty.util.HttpUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

@SpringBootTest
class GulimallThirdPartyApplicationTests {
	@Autowired
	SmsComponent smsComponent;


//	@Test
//	public void testUpload() throws FileNotFoundException {
//
//		//上传文件流。
//		InputStream inputStream = new FileInputStream("F:\\000-File\\图片\\素材\\blog-sc3.jpg");
//		ossClient.putObject("gulimall-genshin","blog2.jpg",inputStream);
//		//关闭OSSCLient
//		ossClient.shutdown();
//		System.out.println("上传完成");
//	}
//}
	@Test
	public void sendsms(){
		smsComponent.sendSmsCode("15736474420", "code:2333");
	}
	@Test
	public void sendSmsCode(){
        String host = "https://wwsms.market.alicloudapi.com";
        String path = "/send_sms";
		String method = "POST";
		String appcode = "7a38e228027d42588940b561f28f81be";
		Map<String, String> headers = new HashMap<String, String>();
		//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
		headers.put("Authorization", "APPCODE " + appcode);
		//根据API的要求，定义相对应的Content-Type
		headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		Map<String, String> querys = new HashMap<String, String>();
		Map<String, String> bodys = new HashMap<String, String>();
		bodys.put("content", "code:1234");
		bodys.put("template_id", "TPL_0000");
		bodys.put("phone_number", "15736474420");


		try {
			HttpResponse response = (HttpResponse) HttpUtils.doPost(host, path, method, headers, querys, bodys);
			System.out.println(response.toString());
			//获取response的body
			//System.out.println(EntityUtils.toString(response.getEntity()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
